package com.mdd.admin.controller.teacher;

import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.teacher.ITeacherService;
import com.mdd.admin.validate.course.CourseParam;
import com.mdd.admin.validate.teacher.TeacherParam;
import com.mdd.admin.validate.common.PageParam;
import com.mdd.admin.vo.teacher.TeacherListVo;
import com.mdd.admin.vo.teacher.TeacherDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 讲师管理
 * @author panweiliang
 */
@RestController
@RequestMapping("api/teacher")
public class TeacherController {

    @Resource
    ITeacherService iTeacherService;

    /**
     * 讲师列表
     *
     * @author panweiliang
     * @param pageParam 分页参数
     * @param params 搜索参数
     * @return Object
     */
    @GetMapping("/list")
    public Object list(@Validated PageParam pageParam,
                       @RequestParam Map<String, String> params) {
        PageResult<TeacherListVo> list = iTeacherService.list(pageParam, params);
        return AjaxResult.success(list);
    }

    /**
     * 获取未下架教师列表
     *
     * @author panweiliang
     * @return Object
     */
    @GetMapping("/get")
    public Object getAll() {
        List<TeacherDetailVo> list = iTeacherService.getAll();
        return AjaxResult.success(list);
    }



    /**
     * 讲师详情
     *
     * @author panweiliang
     * @param id 主键ID
     * @return Object
     */
    @GetMapping("/detail")
    public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        TeacherDetailVo detail = iTeacherService.detail(id);
        return AjaxResult.success(detail);
    }

    /**
     * 讲师新增
     *
     * @author panweiliang
     * @param teacherParam 参数
     * @return Object
     */
    @Log(title = "讲师新增")
    @PostMapping("/add")
    public Object add(@Validated(value = TeacherParam.create.class) @RequestBody TeacherParam teacherParam) {
        iTeacherService.add(teacherParam);
        return AjaxResult.success();
    }

    /**
     * 讲师编辑
     *
     * @author panweiliang
     * @param teacherParam 参数
     * @return Object
     */
    @Log(title = "讲师编辑")
    @PostMapping("/edit")
    public Object edit(@Validated(value = TeacherParam.update.class) @RequestBody TeacherParam teacherParam) {
        iTeacherService.edit(teacherParam);
        return AjaxResult.success();
    }

    /**
     * 讲师删除
     *
     * @author panweiliang
     * @param teacherParam 参数
     * @return Object
     */
    @Log(title = "讲师删除")
    @PostMapping("/del")
    public Object del(@Validated(value = TeacherParam.delete.class) @RequestBody TeacherParam teacherParam) {
        iTeacherService.del(teacherParam.getId());
        return AjaxResult.success();
    }


    /**
     * 课程状态
     *
     * @author panweiliang
     * @param teacherParam 讲师参数
     * @return AjaxResult
     */
    @Log(title = "讲师上下架状态")
    @PostMapping("/change")
    public AjaxResult change(@Validated(value = TeacherParam.change.class)
                             @RequestBody TeacherParam teacherParam) {
        return AjaxResult.success(iTeacherService.changeStatus(teacherParam.getId()));
    }

}
